package com.example.ssm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.ssm.mapper.DrillPlanMapper;
import com.example.ssm.pojo.DrillPlan;
import com.example.ssm.pojo.dto.DrillPlanDTO;
import com.example.ssm.pojo.dto.DrillPlanPageDTO;
import com.example.ssm.pojo.resp.DrillPlanPageResp;
import com.example.ssm.service.DrillPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DrillPlanServiceImpl  extends ServiceImpl<DrillPlanMapper, DrillPlan> implements DrillPlanService {
    @Autowired
    private DrillPlanMapper drillPlanMapper;

    @Override
    public DrillPlan saveDrillPlan(Integer userId, DrillPlanDTO drillPlanDTO) {
        DrillPlan drillPlan = new DrillPlan();
        drillPlan.setApplicationId(drillPlanDTO.getApplicationId());
        drillPlan.setPlanDescription(drillPlanDTO.getPlanDesc());
        drillPlan.setPlanFileUrl(drillPlanDTO.getPlanDocPath());
        drillPlan.setCreatorId(userId.longValue());
        drillPlan.setCreateTime(new Date());
        drillPlan.setUpdateTime(new Date());
        this.saveOrUpdate(drillPlan);
        return drillPlan;
    }

    @Override
    public Boolean audit(Integer userId, Long drillPlanId, String status) {
        DrillPlan drillPlan = drillPlanMapper.selectById(drillPlanId);
        if (drillPlan == null) {
            return false;
        }
        if (!"PENDING".equals(drillPlan.getStatus())) {
            return false;
        }
        drillPlan.setStatus(status);
        drillPlan.setUpdateTime(new Date());
        drillPlanMapper.updateById(drillPlan);
        return true;
    }

    @Override
    public List<DrillPlanPageResp> pageQuery(DrillPlanPageDTO drillPlanPageDTO) {
        
        return null;
    }
}
